<?php
if (!defined('ROOT_PATH')) die('No direct access.');
function view_marketplace($param){
	view_header_top();
	//----------------------------------------------------------------
	$title = "RealiTA - Marketplace";
	$content = "Marketplace";
	$url = MARKETPLACE_URL;
	$image = IMAGE_URL."300x240.gif";
	$desc = "Marketplace untuk semua";
	$auth = "RealiTA";
	$qwords = "marketplace, barang, toko, umkm";
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
	view_header_bottom();
	$head="";
	if (isset($param[1])){
		switch ($param[1]){
			case "fashion" :
				$head = "Fashion";
				break;
			case "elektronik" :
				$head = "Alat Elektronik";
				break;
			case "kesehatan" :
				$head = "Kesehatan & Kecantikan";
				break;
			case "perlengkapan" :
				$head = "Perlengkapan";
				break;
			case "seni" :
				$head = "Kesenian & Kerajinan Tangan";
				break;
			case "hobi" :
				$head = "Hobi & Olahraga";
				break;
			case "kebun" :
				$head = "Kebun & Taman";
				break;
			case "makanan" :
				$head = "Makanan";
				break;
			case "lain" :
				$head = "Lain-lain";
				break;
			default:
				$head = "";
				break;
		}
	}
	$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	if (strpos($url,'?')>0) $url = substr($url,0,strpos($url,'?'));
	$url.="?";
	$tags = (isset($_GET['tags'])) ? $_GET['tags'] : '';
	$url.="tags=".$tags;
	$sort['tipe']='tglReg';
	$sort['by']='DESC';
	if(isset($_GET['snama'])){
		$snama = $_GET['snama'];
		$sort['tipe']='b.nama';
		$sort['by']=$snama;
		$url.="&snama=".$snama;
	}else{
		$snama = 'DESC';
	}
	if(isset($_GET['sharga'])){
		$sharga = $_GET['sharga'];
		$sort['tipe']='b.harga';
		$sort['by']=$sharga;
		$url.="&sharga=".$sharga;
	}else{
		$sharga = 'DESC';
	}
	if(isset($_GET['stgl'])){
		$stgl = $_GET['stgl'];
		$sort['tipe']='tglReg';
		$sort['by']=$stgl;
		$url.="&stgl=".$stgl;
	}else{
		$stgl = 'ASC';
	}
	$tag = explodeTrim(" ",$tags);
	$query = listBarang($param,$tag,$sort);
	$result = paginasi($query,$url,1);
	$contents = $result['sql'];
?>
<!-- Content -->
    <h1>Marketplace <small><?php
		echo $head;
    ?></small></h1>
    <form action="" method="GET">
    <div class="row">
		<div class="small-10 columns">
			<input name="tags" type="text" placeholder="Kata kunci barang">
		</div>
        <div class="small-2 columns">
			<input class="small button" name="c" type="submit" value="Cari" />
        </div>
    </div>
    </form>
    <hr />
	<!-- Nav Sidebar -->
    <!-- This is source ordered to be pulled to the left on larger screens -->
    <div class="large-4 columns ">
      <div class="panel">
          <div class="section-container vertical-nav" data-section data-options="deep_linking: false; one_up: true">
          <section class="section">
            <h5 class="title"><a href="<?php echo MARKETPLACE_URL ?>">SEMUA</a></h5>
          </section>
          <section class="section">
            <h5 class="title"><a href="<?php echo MARKETPLACE_URL."fashion" ?>">Fashion</a></h5>
          </section>
          <section class="section">
            <h5 class="title"><a href="<?php echo MARKETPLACE_URL."elektronik" ?>">Elektronik</a></h5>
          </section>
          <section class="section">
            <h5 class="title"><a href="<?php echo MARKETPLACE_URL."kesehatan" ?>">Kesehatan &amp; Kecantikan</a></h5>
          </section>
          <section class="section">
            <h5 class="title"><a href="<?php echo MARKETPLACE_URL."perlengkapan" ?>">Perlengkapan</a></h5>
          </section>
          <section class="section">
            <h5 class="title"><a href="<?php echo MARKETPLACE_URL."seni" ?>">Kesenian &amp; Kerajinan Tangan</a></h5>
          </section>
          <section class="section">
            <h5 class="title"><a href="<?php echo MARKETPLACE_URL."hobi" ?>">Hobi &amp; Olahraga</a></h5>
          </section>
          <section class="section">
            <h5 class="title"><a href="<?php echo MARKETPLACE_URL."kebun" ?>">Kebun &amp; Taman</a></h5>
          </section>
          <section class="section">
            <h5 class="title"><a href="<?php echo MARKETPLACE_URL."makanan" ?>">Makanan</a></h5>
          </section>
          <section class="section">
            <h5 class="title"><a href="<?php echo MARKETPLACE_URL."lain" ?>">Lain-lain</a></h5>
          </section>
        </div>
      </div>
    </div>
    
    <!-- Main Feed -->
    <!-- This has been source ordered to come first in the markup (and on small devices) but to be to the right of the nav on larger screens -->
    <div class="large-8 columns">
		<div class="row">
			<div class="large-10 columns">
				<?php
					$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
					if (strpos($url,'?')>0) $url = substr($url,0,strpos($url,'?'));
					$snama = ($snama=='DESC') ? 'ASC' : 'DESC';
					$sharga = ($sharga=='DESC') ? 'ASC' : 'DESC';
					$stgl = ($stgl=='ASC') ? 'DESC' : 'ASC';
					$url .= "?tags=$tags";
					echo "Urutkan berdasar : 
							<a href=\"".$url."&snama=$snama"."\">Nama</a> |
							<a href=\"".$url."&sharga=$sharga"."\">Harga</a> |
							<a href=\"".$url."&stgl=$stgl"."\">Tanggal</a>";
				?>
			</div>
		</div>
      <!-- Feed Entry -->
      <br />
      <?php
      if (count($contents)<1) {
		 echo "<h3>TIDAK ADA BARANG</h3>";
	  }
      foreach ($contents as $content) { ?>
      <div class="row">
		  <?php
			if (isset($_SESSION['status-tambah'])) {
				echo "<div class='alert-box success'>".$_SESSION['status-tambah']."<a href='#' class='close'>&times;</a></div>";
				unset($_SESSION['status-tambah']);
			}
			?>
        <div class="large-2 columns small-3"><a href="<?php echo BARANG_URL."a/".$content['idBarang']."/".$content['slug-nama'] ?>"><img src="<?php echo IMAGE_URL ?>80x80.gif" /></div></a>
        <div class="large-10 columns">
          <p><strong><a href="<?php echo BARANG_URL."a/".$content['idBarang']."/".$content['slug-nama'] ?>"><?php echo $content['nama'] ?></a> <a href="<?php echo TOKO_URL."a/".$content['idFB']."/".$content['slug_nama-toko'] ?>">(<?php echo $content['nama-toko'] ?>)</a> : </strong>
          <?php echo $content['deskripsi'] ?>
          <br /><?php echo int_to_rp($content['harga']) ?><a href="<?php echo KERANJANG_URL."beli?id=".$content['idBarang']."&qty=1&beli=Beli" ?>"> <img src="<?php echo IMAGE_URL ?>cart-add.png" /></a>
          </p>
          <ul class="inline-list">
            <li><a href="#" onclick="
    window.open(
      'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href), 
      'facebook-share-dialog', 
      'width=626,height=436'); 
    return false;"><img src="<?php echo IMAGE_URL ?>fb-share-button.gif" /></a></li>
            <li><div class="fb-like" data-href="http://cafe.idebeda.com/ronda-sebagai-programmer/" data-width="The pixel width of the plugin" data-height="The pixel height of the plugin" data-colorscheme="light" data-layout="button_count" data-action="like" data-show-faces="true" data-send="false"></div></li>
            <!--li><a href="">Twitter-Share</a></li-->
          </ul>
        </div>
      </div>
      <!-- End Feed Entry -->
      <hr />
      <?php }
      echo $result['page'];
      /*<div class="row">
		<div class="large-8 small-6 columns">
			<ul class="pagination">
			  <li class="arrow unavailable"><a href="">&laquo;</a></li>
			  <li><a href="">Awal</a></li>
			  <li class="current"><a href="">1</a></li>
			  <li><a href="">2</a></li>
			  <li><a href="">3</a></li>
			  <li><a href="">4</a></li>
			  <li><a href="">Akhir</a></li>
			  <li class="arrow"><a href="">&raquo;</a></li>
			</ul>
		</div>
	</div>*/
echo "</div>";
	view_footer();
}
?>
